package com.shanzmoo.admin.web;

import com.shanzmoo.base.bean.PageRespBase;
import com.shanzmoo.base.bean.SHttpResponse;
import com.shanzmoo.base.bean.SResponse;
import com.shanzmoo.db.personnel.entity.dto.MemberInfoQueryDto;
import com.shanzmoo.db.personnel.entity.dto.MemberInfoSaveDto;
import com.shanzmoo.db.personnel.entity.dto.MemberInfoUpdateDto;
import com.shanzmoo.db.personnel.entity.vo.MemberInfoPageVo;
import com.shanzmoo.db.personnel.entity.vo.MemberInfoVo;
import com.shanzmoo.db.personnel.entity.vo.MemberSelectVo;
import com.shanzmoo.db.personnel.service.IMemberInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 会员信息 前端控制器
 * </p>
 *
 * @author Gzhao
 * @since 2020-12-14
 */
@Api(tags = "人员-会员(客户)管理")
@RestController
@RequestMapping("/api/member")
public class MemberInfoController {

    @Autowired
    private IMemberInfoService memberInfoService;

    @ApiOperation(value = "客户选择列表")
    @GetMapping("/selectList")
    public SHttpResponse<List<MemberSelectVo>> getSelectList() {
        SResponse<List<MemberSelectVo>> re = memberInfoService.getSelectList();
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "新增")
    @PostMapping("/add")
    public SHttpResponse<Boolean> add(@Valid @RequestBody MemberInfoSaveDto saveDto) {
        SResponse<Boolean> re = memberInfoService.add(saveDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "编辑")
    @PostMapping("/edit")
    public SHttpResponse<Boolean> update(@Valid @RequestBody MemberInfoUpdateDto updateDto) {
        SResponse<Boolean> re = memberInfoService.edit(updateDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "分页列表")
    @PostMapping("/pageList")
    public SHttpResponse<PageRespBase<MemberInfoPageVo>> pageList(@Valid @RequestBody MemberInfoQueryDto queryDto) {
        SResponse<PageRespBase<MemberInfoPageVo>> re = memberInfoService.getPageList(queryDto);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "详情")
    @GetMapping("/info")
    public SHttpResponse<MemberInfoVo> getInfo(@ApiParam(value = "用户ID") @RequestParam(value = "id") Integer id) {
        SResponse<MemberInfoVo> re = memberInfoService.getInfo(id);
        return SHttpResponse.transform(re);
    }

    @ApiOperation(value = "详情 -- erp")
    @GetMapping("/infoErp")
    public SHttpResponse<MemberInfoVo> infoErp(@ApiParam(value = "用户ID") @RequestParam(value = "id") Integer id) {
        SResponse<MemberInfoVo> re = memberInfoService.getInfoErp(id);
        return SHttpResponse.transform(re);
    }

}
